# -*- coding:utf-8 -*-
# api/main_business.py

from sanic import Blueprint, request, response
from sanic.log import logger
from sanic_ext import openapi

from business.main_business import get_main_business, get_main_business_detail_by_id

bp_main_business_v1 = Blueprint('MainBusiness', url_prefix='/main_business', version=1)


@bp_main_business_v1.get('/')
@openapi.definition(
    tag='主体业务',
    summary='获取主体业务列表',
    description='获取主体业务列表',
    parameter=[],
)
async def get_main_business_interface(request: request.Request):
    logger.info(f"GET {request.url}")
    data_result = await get_main_business(request)
    return response.json(dict(data_result), content_type='application/json')


@bp_main_business_v1.route('/<main_busi_id>', methods=['GET'])
@openapi.definition(
    tag='主体业务',
    summary='根据ID查询主体业务详情',
    description='根据ID查询主体业务详情',
    parameter=[
        {
            "name": "main_busi_id",
            "type": "int",
            "schema": 1,
            "location": "path",
            "decription": "主体业务ID",
            "required": True,
            "deprecated": None,
            "allowEmptyValue": False,
        }
    ],
)
async def get_main_business_detail_interface(request: request.Request, main_busi_id: int):
    logger.info(f"GET {request.url}")
    data_result = await get_main_business_detail_by_id(main_busi_id, request)
    return response.json(dict(data_result), content_type='application/json')
